<?php

namespace App\Admin\Controllers;

use App\Colleage;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class ColleagueController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('成员');
            
            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('成员资料编辑');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('新建成员');
            //$content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Colleage::class, function (Grid $grid) {

            $grid->id('ID')->sortable();
            $grid->name('姓名')->editable();
            $grid->EngName('英文名')->editable();
            $grid->pic('头像')->image('http://www.ustopmoving.xin/upload/image/',150,150);
            $grid->tel('手机')->editable();
            $grid->email('邮箱')->editable();
            $grid->wechat('微信')->editable();
            $grid->created_at();
            $grid->updated_at();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Colleage::class, function (Form $form) {

            $form->display('id', 'ID');
            $form->text('name', '姓名');
            $form->text('EngName', '英文名');
            $form->image('pic', '头像');
            $form->text('tel', '手机');
            $form->email('email','邮箱');
            $form->text('wechat', '微信');
            
            $form->display('created_at', 'Created At');
            $form->display('updated_at', 'Updated At');
        });
    }
}
